package org.ecshop.controllers;

import java.util.List;

import javax.annotation.Resource;

import org.ecshop.models.GoodsName;
import org.ecshop.models.Users;

import com.opensymphony.xwork2.ModelDriven;

import will.icecoffe.core.DataAccessException;
import will.icecoffe.core.SimpleDataAccessService;

public class LoginController implements ModelDriven<Object>{

	private String userName;
	private String passwd;
	private Users user;

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public void setPasswd(String passwd) {
		this.passwd = passwd;
	}
	
	
	@Resource(name="DAS")
	private SimpleDataAccessService<Users> das;
	
	public String index() throws DataAccessException {
		//System.out.println(this.userName + passwd);
		List<Users> results = das.find("hql", "findUserByUserName", userName);
		System.out.println(userName + passwd + "---------" + (results == null || results.size() == 0));
		if(results == null || results.size() == 0) {
			user = new Users();
		} else
			user = results.get(0);
		
		return null;
	}

	@Override
	public Object getModel() {
		return user;
	}

}
